#!/bin/python3
import http.server, os, random
os.chdir(os.path.dirname(__file__))
songs = os.popen('basename -s.mp3 *.mp3').read().split()
class handler(http.server.BaseHTTPRequestHandler):
    def do_GET(self):
        if '/' == self.path:
            self.wfile.write(b'<audio autoplay controls onended=load() src=0>')
        if '/0' == self.path:
            with open(f'{random.choice(songs)}.mp3', 'br') as f:
                self.wfile.write(f.read())
http.server.HTTPServer(('',8000),handler).serve_forever()
